<?php
require(dirname(dirname(__FILE__))."/Config/config.php");
require(dirname(dirname(__FILE__))."/jssdk.php");
class npcController extends appController{
    
    public function getHomeInfo()
    {
        $m = Model('npc');
        $res = $m->getHomeInfo();
        die($_REQUEST['callback']."(".json_encode($res).")");
    }
    public function index()
    {
//         $_SESSION['wxid'] = 23498;
        $this->check_member();
        $m = Model('npc');
        //微信分享参数构建
        $jsdk = $m ->get_jsdk();
        $this->assign("jsdk", $jsdk);
        $config[c] = array('site_name' => "全国两会特别报道");
        $this->assign_global($config);
        $id = $m->isExitNpc($_GET['id']);
//         $id = $_GET['id'];
        $m->add_sub_number("npc","see_num", "+1", $id);
        $npc = $m->getOldestNpc($id);
        $this->assign("npc", $npc);
    
        $this->display('index.html');
    }
    
    public function zan()
    {
        $wxid = yf_empty($_SESSION['wxid'],"请重新登录后再点赞");
        $nid = yf_empty($_REQUEST['nid'],"请选择点赞评论");
        $result = Model('npc')->zan($wxid,$nid);
        $result['error'] = 0;
        $this->showMsg($result);
    }
    
    public function sendComment()
    {
        $wxid = yf_empty($_SESSION['wxid'],"请重新登录后再评论");
        $comment = yf_empty($_REQUEST["comment"],"请说几句吧，谢谢~");
        $nid = yf_empty($_REQUEST["nid"],"请刷新后重新登录吧，谢谢~");
        $result = Model('npc')->sendComment($wxid,$comment,$nid);
        $this->showMsg($result);
    }
    
    public function addShareNum()
    {
        $id = yf_empty($_GET['id'],"分享添加失败");
        $m = Model('npc');
        $res = $m->add_sub_number("npc","forward_num", "+1", $id);
        $this->showMsg(array("error"=>0));
    }
}